package mx.itesm.twritter.shared.map;

import java.util.List;
import java.util.Map;

import com.google.gwt.user.client.rpc.IsSerializable;

public class Way implements IsSerializable, Comparable<Way> {
	
	private int id;
	private String name; // shortcut for the street's name
	private List<Node> nodes; // prefer ArrayList
	private Map<String, String> tags;
	
	public Way(int id, String name, List<Node> nodes) {
		this.id = id;
		this.nodes = nodes;
		this.name = name;
	}
	
	public Way(int id, String name, List<Node> nodes, Map<String, String> tags) {
		this.id = id;
		this.nodes = nodes;
		this.name = name;
		this.tags = tags;
	}
	

	public String toString() {
		String ret = "Way " + id + ", " + name + ":\n";
		for(int i=0; i<nodes.size(); i++) {
			//ret += "  " + nodes.get(i).toStringWithoutCrosses() + "\n";
			ret += "  " + nodes.get(i) + "\n";
		}
		return ret;
	}
	
	public boolean hasBothNodes(Node a, Node b) {
		return this.nodes.contains(a) && this.nodes.contains(b);
	}
	
	@Override
	public boolean equals (Object o) {
		if(!(o instanceof Way)) {
			return false;
		}
		Way w = (Way)o;
		
		return this.id == w.getId();
	}
	
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	public List<Node> getNodes() {
		return nodes;
	}
	public void setNodes(List<Node> nodes) {
		this.nodes = nodes;
	}
	
	public Map<String, String> getTags() {
		return tags;
	}
	public void setTags(Map<String, String> tags) {
		this.tags = tags;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public int compareTo(Way o) {
		return this.id - o.getId();
	}
	
}
